package lgkj.meicqt20.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;
import lgkj.meicqt20.bean.VideoTypeEntity;


/**
 * Created by Administrator on 2017/8/7 0007.
 */

public class VideoTypeAdapter extends BaseAdapter {
    private List<VideoTypeEntity.DataBean> data;
    private Context context;

    public void setPosition(int position) {
        if (position >= 0 && position <= data.size()) {
            this.position = position;
        }
    }

    private int position = 0;

    public VideoTypeAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    public void setData(List<VideoTypeEntity.DataBean> data) {
        if (data != null) {
            this.data.clear();
            this.data = data;
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_video_type, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_name = (TextView) view.findViewById(R.id.tv_name);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv_name.setText(data.get(i).getType().getVideo_type_name());
        if (position == i) {
            viewHolder.tv_name.setBackgroundResource(R.drawable.video_name_item);
        } else {
            viewHolder.tv_name.setBackgroundColor(0);
        }
        return view;
    }

    class ViewHolder {
        TextView tv_name;
    }
}
